

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 网站用户 iframe 框</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <script src="../../../layuiadmin/jquery.min.js"></script>
</head>
<body>
<form class="layui-form" action="">
  <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
    <input type="hidden" id="head" >
    <input type="hidden" id="id" value="{$user.id|default=''}" >

    <div class="layui-form-item">
      <label class="layui-form-label">题目</label>
      <div class="layui-input-inline">
        <input type="text" name="topic" id="topic" lay-verify="required" value="{$user['topic']|default=''}"  autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">蓝牙</label>
      <div class="layui-input-inline">
        <input type="text" name="ble" id="ble"  value="{$user['ble']|default=''}"  autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">正确答案</label>
      <div class="layui-input-inline">
        <input type="text" name="correct" id="correct"  value="{$user['correct']|default=''}" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">A的答案</label>
      <div class="layui-input-inline">
        <input type="text" name="one" id="one"  value="{$user['one']|default=''}" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">B的答案</label>
      <div class="layui-input-inline">
        <input type="text" name="two" id="two"  value="{$user['two']|default=''}" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">C的答案</label>
      <div class="layui-input-inline">
        <input type="text" name="three" id="three"  value="{$user['three']|default=''}" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">D的答案</label>
      <div class="layui-input-inline">
        <input type="text" name="four" id="four"  value="{$user['four']|default=''}" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
          <label class="layui-form-label">所属线路id</label>
          <div class="layui-input-inline">
              <input type="text" name="subordinate" id="subordinate"  value="{$user['subordinate']|default=''}" placeholder="" autocomplete="off" class="layui-input">
          </div>
    </div>


    <!--<div class="layui-form-item">-->
      <!--<label class="layui-form-label">健康情况</label>-->
      <!--<div class="layui-input-inline">-->
        <!--<input type="text" name="fitness" id="age"  value="{$user['fitness']|default=''}" placeholder="" autocomplete="off" class="layui-input">-->
      <!--</div>-->
    <!--</div>-->

    <div class="layui-form-item">
      <!--<label class="layui-form-label">头像</label>-->
      <div class="layui-input-inline">
        <!--{if isset($cate['cate_img'])}<img class="img" width="100" height="100" src="{$cate['cate_img']|default=''}"/>-->
        <!--{else}-->
        <!--<img class="img" width="100" height="100" style="display: none" src="" />-->
        <!--{/if}-->
        <!--<form id="form1">-->
        <!--<input type="file" class="imgInput" value="" id="img_src" onchange ="uploadFile(this,1)" placeholder="" name="uploadkey">-->
        <!--</form>-->
      </div>


      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" onclick="add_user()">提交</button>
        </div>
      </div>
      <input type="hidden" id="identity_auth"  value="{$user['identity_auth']|default=''}" >
  </div>
</form>
  <script src="../../../layuiadmin/layui/layui.js"></script>
  <script>
      //添加用户
      function add_user(){
          event.preventDefault();
          var topic =$("#topic").val();
          var ble =$("#ble").val();
          var correct =$("#correct").val();
          var one =$("#one").val();
          var two =$("#two").val();
          var three =$("#three").val();
          var four =$("#four").val();
          var subordinate =$("#subordinate").val();
          var identity_auth=$('#identity_auth').val();
          if($("#id").val()=="")
          {
            $.ajax({
                url: "{:url('add_item')}",
                data: {
                    topic:topic,
                    ble:ble,
                    correct:correct,
                    one:one,
                    two:two,
                    three:three,
                    four:four,
                    subordinate:subordinate
                },
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if(data.data==201)
                    {
                        layer.msg(data.msg);
                    }
                    else
                    {
                        layer.msg(data.msg, {
                            icon: 1, time: 1000, end: function () {
                                window.parent.location.reload();//刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }
                        });
                    }
                }
            })
          }
          else
          {
              $.ajax({
                  url: "{:url('editing')}",
                  data: {id:id,nickname:nickname,phone:phone,age:age},
                  type: 'post',
                  dataType: 'json',
                  success: function (data) {
                      if(data.data==201) {
                          layer.msg(data.msg);
                      }
                      else {
                          layer.msg(data.msg, {
                              icon: 1, time: 1000, end: function () {
                                  window.parent.location.reload();//刷新父页面
                                  var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                  parent.layer.close(index);
                              }
                          });
                      }
                  }
              })
          }
      }
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'upload'], function(){
    var $ = layui.$
    ,form = layui.form
    ,upload = layui.upload ;
    
    upload.render({
      elem: '#layuiadmin-upload-useradmin'
      ,url: layui.setter.base + 'json/upload/demo.js'
      ,accept: 'images'
      ,method: 'get'
      ,acceptMime: 'image/*'
      ,done: function(res){
        $(this.item).prev("div").children("input").val(res.data.src)
      }
    });


      //普通图片上传
      var uploadInst = upload.render({
          elem: '#test1'
          ,url: "{:url('upload')}"
          ,before: function(obj){
              //预读本地文件示例，不支持ie8
              obj.preview(function(index, file, result){
                  $('#demo1').attr('src', result); //图片链接（base64）
              });
          }
          ,done: function(res){
              //如果上传失败
              if(res.code > 0){
                  return layer.msg('上传失败');
              }

              $('#head').val(res.count);
              //上传成功
          }
          ,error: function(){
              //演示失败状态，并实现重传
              var demoText = $('#demoText');
              demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
              demoText.find('.demo-reload').on('click', function(){
                  uploadInst.upload();
              });
          }
      });

  })

      layui.use('form', function(){
          var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

          //……

          form.on('radio(erweima)', function (data) {
              //alert(data.elem);
              //console.log(data.elem);
              var abc=data.value;
              if(abc==1){
                  $("#identity_auth").val(1);
                  // alert($("#zjidian").val());
              }else{
                  $("#identity_auth").val(0);
                  //  alert($("#rjidian").val());
              }


          });
          //但是，如果你的HTML是动态生成的，自动渲染就会失效
          //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
          form.render();
      });



  </script>
</body>
</html>